package vn.pdg.zoombie.ui;

import java.io.File;

import vn.pdg.zoombie.bean.Utils;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.Window;

public class TakePhoto extends Activity{

	private final int REQUEST_CODE_CAMERA = 1;
	private final int REQUEST_CODE_ADJUST_PHOTO = 2;
	private final String pathImage = "/mnt/sdcard/template.jpg";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		startCamera();
	}
	
	private void startCamera(){
		Uri uriCamera = Uri.fromFile(new File(pathImage));
		Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
		intent.putExtra(MediaStore.EXTRA_OUTPUT, uriCamera);
		intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
		startActivityForResult(intent, REQUEST_CODE_CAMERA);
		
	}
	
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		switch (requestCode) {
		case REQUEST_CODE_CAMERA:
			
			/**
			 * take image is successful
			 */
			if(resultCode == RESULT_OK){
				String orientation = String.valueOf(Utils.getOrientation(pathImage));
				
				Intent intent = new Intent(TakePhoto.this,AdjustPhoto.class);
				intent.putExtra(AdjustPhoto.EXTRA_URL_PHOTO, pathImage);
				intent.putExtra(AdjustPhoto.EXTRA_ORIENT_PHOTO, orientation);
				startActivity(intent);
				finish();
				
				// take image is canc
			}else{
				finish();
			}
			
			break;
		case REQUEST_CODE_ADJUST_PHOTO:
			
			break;
		default:
			break;
		}
		
		
	}
}
